package com.iweb.user.controller;


import com.iweb.user.model.User;
import com.iweb.user.resp.R;
import com.iweb.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jack
 * @since 2024-09-20
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("list")
    public R<List<User>> list() {
        List<User> list = userService.list();
        return R.SUCCESS("list", list);
    }

    @PostMapping("addUser")
    public R<String> addUser(@RequestBody User user) throws Exception {
        userService.saveUser(user); // 如果没有异常则说明 插入成功
        return R.SUCCESS("add user", "ok");
    }

}

